module utils {
	
	export class Toast extends eui.Component
	{
        private static _instance: utils.Toast;
        public bg:eui.Rect;
        public msgTxt:eui.Label;
        public stageContainer:egret.Stage;
    	
		public constructor() 
		{
    		super();
            this.skinName = "resource/eui_skins/ToastSkin.exml";
            this.touchEnabled=false;
		}

        public setStageContainer(stageContainer:egret.Stage):void
        {
            this.stageContainer=stageContainer;
            this.width=utils.CoreData.instance.screenW;
            this.scaleX=1/utils.CoreData.instance.stageScale;
            this.scaleY=1/utils.CoreData.instance.stageScale;
            this.x=0;
            this.y=(document.documentElement.clientHeight-this.height)/2;
        }
		
        public static get instance(): utils.Toast
        {
            if(!this._instance) 
            {
                this._instance = new utils.Toast();
            }
            return this._instance;
        }

        public showMsg(msg:string):void
        {
            this.alpha=0;
            this.msgTxt.text=msg;
            this.bg.width=this.msgTxt.width+80;
            TweenMax.killTweensOf(this);
            this.stageContainer.addChild(this);
            TweenMax.to(this,0.4,{ alpha: 1,ease: Cubic.easeInOut,onComplete: () => { this.dispear();}});
            // this.msgTxt.horizontalCenter=0;
            // this.bg.horizontalCenter=0;
        }

        public dispear():void
        {
            TweenMax.to(this,0.2,{delay:1.5, alpha: 0,ease: Cubic.easeInOut,onComplete: () => { 
                if(this.parent) this.parent.removeChild(this);
            }});
        }
        
	}
}
